
# Creates Figure 1
# Run "Rep_F1_G1_J1_J2_Prep_Fig1.do" first
# Only thing to change below is the working directory

library(foreign)
library(devtools)
library(haven)
require(graphics)
library(xtable)

remove(list=objects())


pdf(file="C:/Users/Peter/Dropbox/drc_womenempowerment/03_analysis/Fig1_main.pdf", width=12, height=5)

data <- read.dta("C:/Users/Peter/Dropbox/drc_womenempowerment/03_analysis/results.dta", convert.factors=F)
data <- data.frame(data)
attach(data)

# SETUP
par(mfrow=c(1,3))
insidemarup = c(4, 6.7, 3, 0.5) # b, l, t, r 
axislabelsize=1.5
maintitlesize=2

par(mar=insidemarup)
par(mgp = c(4, 1, 0))

X <- "black"
Y <- "black"
Z <- "white"


############################################################################ LEFT

plot(0,0, xlim=c(-0.4,0.4), ylim=c(0.5,5.5), xlab="", ylab="", cex.lab=axislabelsize, axes=F, frame.plot=T, type="n", 
     main="Community & Household", cex.main=maintitlesize, family = 'serif')
axis(1, at=seq(-1,1,0.2), cex.axis=axislabelsize, las=1, family = 'serif')				
axis(2, at=seq(1,5,1), labels=c("Violence", "Time-use", "Committee", "Discussion", "Presence"), cex.axis=axislabelsize, padj=0, family = 'serif',las=1)

mtext(side = 1, text = "Estimate", line = 2, family = 'serif', cex=1)

abline(v=0, col="gray")

## Community: Presence
points(estimate[21], 5, pch=15, cex=2, col=`Y`)
lines(c(max95[21],min95[21]),c(5,5), col=`Y`)
lines(c(min95[21],min95[21]),c(5-0.1,5+0.1), col=`Y`)
lines(c(max95[21],max95[21]),c(5-0.1,5+0.1), col=`Y`)

## Community: Participation
points(estimate[23], 4, pch=15, cex=2, col=`Y`)
lines(c(max95[23],min95[23]),c(4,4), col=`Y`)
lines(c(min95[23],min95[23]),c(4-0.1,4+0.1), col=`Y`)
lines(c(max95[23],max95[23]),c(4-0.1,4+0.1), col=`Y`)

## Community: Member
points(estimate[25], 3, pch=15, cex=2, col=`Y`)
lines(c(max95[25],min95[25]),c(3,3), col=`Y`)
lines(c(min95[25],min95[25]),c(3-0.1,3+0.1), col=`Y`)
lines(c(max95[25],max95[25]),c(3-0.1,3+0.1), col=`Y`)

## Household: Daily
points(estimate[27], 2.1, pch=19, cex=2, col=`X`)
lines(c(max95[27],min95[27]),c(2.1,2.1), col=`X`)
lines(c(min95[27],min95[27]),c(2.1-0.1,2.1+0.1), col=`X`)
lines(c(max95[27],max95[27]),c(2.1-0.1,2.1+0.1), col=`X`)
lines(c(max95[29],min95[29]),c(1.9,1.9), col=`Y`)
lines(c(min95[29],min95[29]),c(1.9-0.1,1.9+0.1), col=`Y`)
lines(c(max95[29],max95[29]),c(1.9-0.1,1.9+0.1), col=`Y`)
points(estimate[29], 1.9, pch=21, cex=2, bg=`Z`)

## Household: List
points(estimate[33], 1.1, pch=19, cex=2, col=`X`)
lines(c(max95[33],min95[33]),c(1.1,1.1), col=`X`)
lines(c(min95[33],min95[33]),c(1.1-0.1,1.1+0.1), col=`X`)
lines(c(max95[33],max95[33]),c(1.1-0.1,1.1+0.1), col=`X`)
lines(c(max95[37],min95[37]),c(0.9,0.9), col=`Y`)
lines(c(min95[37],min95[37]),c(0.9-0.1,0.9+0.1), col=`Y`)
lines(c(max95[37],max95[37]),c(0.9-0.1,0.9+0.1), col=`Y`)
points(estimate[37], 0.9, pch=21, cex=2, bg=`Z`)

legend(0.19,1.1, c("Women","Men"), pch=c(19,21), col=c(`X`,`X`), cex=1.3, bty="y", horiz=F)	


abline(h=2.5, col="black")

############################################################################ CENTER

plot(0,0, xlim=c(-0.4,0.4), ylim=c(0.5,5.5), xlab="", ylab="", cex.lab=axislabelsize, axes=F, frame.plot=T, type="n", 
     main="Project Selection", cex.main=maintitlesize, family = 'serif')
axis(1, at=seq(-1,1,0.2), cex.axis=axislabelsize, las=1, family = 'serif')				
axis(2, at=seq(1,5,1), labels=c("Agri.", "Watsan", "Transport", "Education", "Health"), cex.axis=axislabelsize, padj=0, family = 'serif',las=1)

mtext(side = 1, text = "Estimate", line = 2, family = 'serif', cex=1)

abline(v=0, col="gray")

## Community: Health
points(estimate[39], 5, pch=15, cex=2, col=`Y`)
lines(c(max95[39],min95[39]),c(5,5), col=`Y`)
lines(c(min95[39],min95[39]),c(5-0.1,5+0.1), col=`Y`)
lines(c(max95[39],max95[39]),c(5-0.1,5+0.1), col=`Y`)

## Community: Education
points(estimate[41], 4, pch=15, cex=2, col=`Y`)
lines(c(max95[41],min95[41]),c(4,4), col=`Y`)
lines(c(min95[41],min95[41]),c(4-0.1,4+0.1), col=`Y`)
lines(c(max95[41],max95[41]),c(4-0.1,4+0.1), col=`Y`)

## Community: Transport
points(estimate[43], 3, pch=15, cex=2, col=`Y`)
lines(c(max95[43],min95[43]),c(3,3), col=`Y`)
lines(c(min95[43],min95[43]),c(3-0.1,3+0.1), col=`Y`)
lines(c(max95[43],max95[43]),c(3-0.1,3+0.1), col=`Y`)

## Community: Watsan
points(estimate[45], 2, pch=15, cex=2, col=`Y`)
lines(c(max95[45],min95[45]),c(2,2), col=`Y`)
lines(c(min95[45],min95[45]),c(2-0.1,2+0.1), col=`Y`)
lines(c(max95[45],max95[45]),c(2-0.1,2+0.1), col=`Y`)

## Community: Agriculture
points(estimate[46], 1, pch=15, cex=2, col=`Y`)
lines(c(max95[46],min95[46]),c(1,1), col=`Y`)
lines(c(min95[46],min95[46]),c(1-0.1,1+0.1), col=`Y`)
lines(c(max95[46],max95[46]),c(1-0.1,1+0.1), col=`Y`)

############################################################################ RIGHT

plot(0,0, xlim=c(-0.4,0.4), ylim=c(0.5,5.5), xlab="", ylab="", cex.lab=axislabelsize, axes=F, frame.plot=T, type="n", 
     main="Attitudes", cex.main=maintitlesize, family = 'serif')
axis(1, at=seq(-1,1,0.2), cex.axis=axislabelsize, las=1, family = 'serif')				
axis(2, at=seq(1,5,1), labels=c("Index", "Leader2", "Leader1", "Complain", "Equality"), cex.axis=axislabelsize, padj=0, family = 'serif',las=1)

mtext(side = 1, text = "Estimate", line = 2, family = 'serif', cex=1)

abline(v=0, col="gray")

## Attitudes: Equality
points(estimate[1], 5.1, pch=19, cex=2, col=`X`)
lines(c(max95[1],min95[1]),c(5.1,5.1), col=`X`)
lines(c(min95[1],min95[1]),c(5.1-0.1,5.1+0.1), col=`X`)
lines(c(max95[1],max95[1]),c(5.1-0.1,5.1+0.1), col=`X`)
lines(c(max95[3],min95[3]),c(4.9,4.9))
lines(c(min95[3],min95[3]),c(4.9-0.1,4.9+0.1))
lines(c(max95[3],max95[3]),c(4.9-0.1,4.9+0.1))
points(estimate[3], 4.9, pch=21, cex=2, bg=`Z`)

## Attitudes: Complain
points(estimate[5], 4.1, pch=19, cex=2, col=`X`)
lines(c(max95[5],min95[5]),c(4.1,4.1), col=`X`)
lines(c(min95[5],min95[5]),c(4.1-0.1,4.1+0.1), col=`X`)
lines(c(max95[5],max95[5]),c(4.1-0.1,4.1+0.1), col=`X`)
lines(c(max95[7],min95[7]),c(3.9,3.9))
lines(c(min95[7],min95[7]),c(3.9-0.1,3.9+0.1))
lines(c(max95[7],max95[7]),c(3.9-0.1,3.9+0.1))
points(estimate[7], 3.9, pch=21, cex=2, bg=`Z`)

## Attitudes: Leader1
points(estimate[9], 3.1, pch=19, cex=2, col=`X`)
lines(c(max95[9],min95[9]),c(3.1,3.1), col=`X`)
lines(c(min95[9],min95[9]),c(3.1-0.1,3.1+0.1), col=`X`)
lines(c(max95[9],max95[9]),c(3.1-0.1,3.1+0.1), col=`X`)
lines(c(max95[11],min95[11]),c(2.9,2.9))
lines(c(min95[11],min95[11]),c(2.9-0.1,2.9+0.1))
lines(c(max95[11],max95[11]),c(2.9-0.1,2.9+0.1))
points(estimate[11], 2.9, pch=21, cex=2, bg=`Z`)

## Attitudes: Leader2
points(estimate[13], 2.1, pch=19, cex=2, col=`X`)
lines(c(max95[13],min95[13]),c(2.1,2.1), col=`X`)
lines(c(min95[13],min95[13]),c(2.1-0.1,2.1+0.1), col=`X`)
lines(c(max95[13],max95[13]),c(2.1-0.1,2.1+0.1), col=`X`)
lines(c(max95[15],min95[15]),c(1.9,1.9))
lines(c(min95[15],min95[15]),c(1.9-0.1,1.9+0.1))
lines(c(max95[15],max95[15]),c(1.9-0.1,1.9+0.1))
points(estimate[15], 1.9, pch=21, cex=2, bg=`Z`)

## Attitudes: Index
points(estimate[17], 1.1, pch=19, cex=2, col=`X`)
lines(c(max95[17],min95[17]),c(1.1,1.1), col=`X`)
lines(c(min95[17],min95[17]),c(1.1-0.1,1.1+0.1), col=`X`)
lines(c(max95[17],max95[17]),c(1.1-0.1,1.1+0.1), col=`X`)
lines(c(max95[19],min95[19]),c(0.9,0.9))
lines(c(min95[19],min95[19]),c(0.9-0.1,0.9+0.1))
lines(c(max95[19],max95[19]),c(0.9-0.1,0.9+0.1))
points(estimate[19], 0.9, pch=21, cex=2, bg=`Z`)

legend(0.19,1.1, c("Women","Men"), pch=c(19,21), col=c(`X`,`X`), cex=1.3, bty="y", horiz=F)	

dev.off()

